

var api     = require('../../utils/api.js');
var WxParse = require('../../wxParse/wxParse.js');
var app     = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        api.get({
            url: 'index/getrulebyid?id=' + options.id,
            data: {},
            success: data => {
                
                    var content=this.formatRichText(data.data.content);


                    WxParse.wxParse('articleContent', 'html', content, this, 30);
             
            },
            fail: err => {
                wx.hideNavigationBarLoading();
            }
        });
    },

    formatRichText(html) {
        //控制小程序中图片大小
        let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
            console.log(match.search(/style=/gi));
            if (match.search(/style=/gi) == -1) {
                match = match.replace(/\<img/gi, '<img style=""');
            }
            return match;
        });

        newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
        newContent = newContent.replace(/<br[^>]*\/>/gi, '');
        return newContent;
    },

})